<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>添加物业账户</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/admin.css"/>
    <link rel="stylesheet" type="text/css" href="../css/lift.css">
    <style>
    .layui-form{
    width: 350px;
    height:300px;
    margin:0 auto;
    }
    .add-name th{
      width:100px;
      height:40px;
      font-size:14px;
      padding: 0;
      vertical-align: middle;
    }
    .add-name input{
      outline:none;
      width:160px;
      height: 28px;
      border:1px solid #E5BA70;
      border-radius:5px;
    }
    .tianjia-checkBox th{
      width:88px;
      height:40px;
      font-size:18px;
      padding-top:20px;
    }
    tr.tianjia-checkBox td input{
      margin-left:10px;
      display: inline-block;
    }
    .layui-table td, .layui-table th{
      padding:3px 12px;
    }
    .layui-form h3,.layui-form .role_name{
      margin-left:30px;
      margin-bottom:10px;
    }
    .layui-form .role_name{
      width:145px;
      height:25px;
       border-radius:5px;
       border:1px solid #888;
       display:inline-block;
    }
    .layui-form .layui-table{
        margin-top:50px;
        margin:0 auto;
    }
    .layui-input-block  span{
      font-size: 14px;
    }
    .layui-input-block th{
       font-size: 14px;
    }
    #btn-c,#btn-s{
      border:0;
      width: 100px;
      height: 28px;
      margin-top:15px;
      border-radius:5px;
      background-color: #D8D8D8;
    }
    #btn-c{
       margin-left:70px;
    }
    #btn-s:hover,#btn-c:hover{
      color:#fff;
     background-color:#EF7632;
    }
    #btn-s{
        margin-left:15px;
    }
    .layui-layer .layui-layer-title{
      background-color: #fff;
    }
    .layui-form-radio{
      padding:0;
      margin:0;
      margin-left:90px;
    }
 .layui-table-add{
  margin-left:30px;
 }
 </style>
</head>
<body>
     <form class="layui-form" action="">

   <h3 style="display:inline-block">物业公司</h3>
     <input type="text" class="role_name" id="company_name" value="" placeholder="&emsp;如：银泰物业"  onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value" /> <br>
  <h3 style="display:inline-block">用户名称</h3>
     <input type="text" class="role_name"  id="user_name" value="" placeholder="&emsp;如：王小小"  onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value" /><br>
  <h3 style="display:inline-block">账&emsp;&emsp;号</h3>
     <input type="text"  class="role_name" id="user_tel" value="" placeholder="&emsp;输入11位手机号" onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value" /><br>
   <h3>账户角色:&emsp;</h3>
     <table class="layui-table layui-table-add" lay-skin="nob" id="table">
            <tbody  id="admin">
          </tbody>
        </table>
          <input type="button" id="btn-c" value="取消">
          <input type="button" id="btn-s" value="保存">
      </form>
  <script src="../lib/jquery.js" type="text/javascript"></script>
  <script type="text/javascript" src="../layui/layui.js"></script>
  <script src="../lib/js/jquery.cookie.js" type="text/javascript"></script>
  <script>
      layui.use(['jquery','form','upload','layer'], function(){
            var $ = layui.jquery,layer = layui.layer;
            var element = layui.element;
                form = layui.form();
            var params={};
            var current_page = 1;

     $.ajax({
          url: '../../role_manage/queryWuyeRoles',
          type: 'get',
          dataType: 'json',
          data:{
              current_page: current_page ||1,
              limit:10
               }
            })
          .done(function(response){
             console.log(response);
          if(response.resultCode == '200'){
             console.log("success");
           var str= '';
            console.log(response.page.list.length);
          if(response.page.list.length){
            tableData = response.page.list;
            for(var i=0;i<response.page.list.length;i++){
            str +=
             '<tr data-id="'+response.page.list[i].role_id+'">'+
            '<td class="check"><input data-id="'+response.page.list[i].role_id+'" type="radio" name="items" value="'+response.page.list[i].role_name+'" title="'
            +response.page.list[i].role_name+'" lay-skin="line"></td>'+
            '</tr>'
          }
          $("#admin").html(str);
           form.render();
          }
         }
        })
           .fail(function(response){
              console.log("fail");
              if(response.resultCode=='001'){
                console.log("param is not found");
                }else if(response.resultCode=='009'){
                  console.log("String is not int type");
                }
            })

//获取表单中数据保存
      $("#btn-s").off("click").on("click",function(){
          var company_name = $("#company_name").val();
              console.log('company_name',company_name);
              params.company_name = company_name;

          var user_name = $("#user_name").val();
              console.log('user_name',user_name);
              params.user_name = user_name;

          var user_tel = $("#user_tel").val();
              console.log('user_tel',user_tel);
              params.user_tel = user_tel;

          var role_name= $("input[name='items']:checked").attr("value");
              console.log('role_name',role_name);
              params.role_name = role_name;

          var user_id = localStorage.getItem("user_id");
              params.superior_id  = user_id;

          var role_id= $("input[name='items']:checked").attr("data-id");
              console.log('role_id',role_id);
              params.role_id  = role_id;

       if(company_name&&user_name&&user_tel){
         $.ajax({
           url: '../../wuye_account/addWuYeUser',
           type: 'POST',
           dataType: 'json',
           data: params,
          })
           .done(function(response){
               console.log("success",response);
               window.parent.location.reload();
               var index=parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
               alert("添加账号成功");
          })
         .fail(function(response){
                 window.parent.location.reload();
                 var index=parent.layer.getFrameIndex(window.name);
                 parent.layer.close(index);
                alert("添加账号失败");
              if(response.resultCode=='001'){
                  console.log("param is not found")
                }else if(response.resultCode=='009'){
                  console.log("String is not int tpye")
                 }else if(response.resultCode=='002'){
                  console.log("Phone number is not vaild")
                 }
            })
      }
    })
   $("#btn-c").click(function(){
        window.parent.location.reload();
        var index=parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
     })
        });
  </script>
</body>
</html>
